<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	session.setAttribute("basePath", basePath);
%>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<base href="${basePath }">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="description" content="">
<meta name="author" content="">
<title>西普茗茶商品优惠券-${coupon.couponName }</title>
<meta name="renderer" content="webkit">

<!-- BEGIN GLOBAL MANDATORY STYLES -->
<link href="https://cdn.bootcss.com/font-awesome/4.0.3/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
<link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<link href="assets/plugins/uniform/css/uniform.default.css" rel="stylesheet" type="text/css" />
<link href="assets/css/animate.css" rel="stylesheet" type="text/css" />
<!-- END GLOBAL MANDATORY STYLES -->
<!-- BEGIN PAGE LEVEL STYLES -->
<link href="https://cdn.bootcss.com/Swiper/3.0.8/css/swiper.min.css" rel="stylesheet" type="text/css" />
<!-- END PAGE LEVEL STYLES -->
<!-- BEGIN THEME STYLES -->
<link href="assets/css/style-metronic.css" rel="stylesheet" type="text/css" />
<link href="assets/css/style.css" rel="stylesheet" type="text/css" />
<link href="assets/css/style-responsive.css" rel="stylesheet" type="text/css" />
<link href="assets/css/plugins.css" rel="stylesheet" type="text/css" />
<link href="assets/css/themes/light.css" rel="stylesheet" type="text/css" id="style_color" />
<link href="assets/css/print.css" rel="stylesheet" type="text/css" media="print" />
<link href="assets/css/custom.css" rel="stylesheet" type="text/css" />
<!-- END THEME STYLES -->
<link rel="shortcut icon" href="favicon.ico" />

<script type="text/javascript">
	var isHTML5 = true;
</script>
<!--[if lt IE 9]>
    <script src="https://cdn.bootcss.com/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
	<script src="js/excanvas.min.js"></script> 
    <script type="text/javascript">
		isHTML5 = false;
	</script>
<![endif]-->
<style type="text/css">
</style>
</head>
<!--/head-->
<!-- BEGIN BODY -->
<body class="page-footer-fixed">
	<c:choose>
		<c:when test="${coupon==null}">
			<h2 class="text-center" style="margin: 50px 5px;">
				<strong>没有找到此优惠券</strong>
			</h2>
		</c:when>
		<c:when test="${coupon!=null&&before==true}">
			<h2 class="text-center" style="margin: 50px 5px;">
				<strong>还没到抢购优惠券时间</strong>
			</h2>
		</c:when>
		<c:when test="${coupon!=null&&after==true}">
			<h2 class="text-center" style="margin: 50px 5px;">
				<strong>已经过了抢购优惠券时间</strong>
			</h2>
		</c:when>
		<c:when test="${coupon!=null&&coupon.couponNumber<=0}">
			<h2 class="text-center" style="margin: 50px 5px;">
				<strong>已经抢光了</strong>
			</h2>
		</c:when>
		<c:otherwise>
			<input type="hidden" id="coupon_id" value="${coupon.couponId }">
			<div class="container">
				<div style="margin: 30px 5px;">
					<div class="dashboard-stat yellow" style="border: dotted 2px orange;">
						<div class="visual">
							<i class="fa fa-gift"></i>
						</div>
						<div class="details">
							<div class="number">
								<c:choose>
									<c:when test="${coupon.couponType=='满减' }">
										<strong><fmt:formatNumber type="number" value="${coupon.param2 }" maxFractionDigits="0" /></strong> 元优惠券
									</c:when>
									<c:when test="${coupon.couponType=='立减' }">
										<strong><fmt:formatNumber type="number" value="${coupon.param1 }" maxFractionDigits="0" /></strong> 元优惠券
									</c:when>
								</c:choose>
							</div>
							<div class="desc">
								<c:choose>
									<c:when test="${coupon.couponType=='满减' }">
									满<fmt:formatNumber type="number" value="${coupon.param1 }" maxFractionDigits="0" />减<fmt:formatNumber type="number" value="${coupon.param2 }" maxFractionDigits="0" />元
									</c:when>
									<c:when test="${coupon.couponType=='立减' }">
									立减<fmt:formatNumber type="number" value="${coupon.param1 }" maxFractionDigits="0" />元
									</c:when>
								</c:choose>
							</div>
						</div>
						<a class="more" href="javascript:void(0)">
							西普茗茶商品优惠券 <i><fmt:formatDate value="${coupon.couponUseBeginTime }" pattern="yyyy.MM.dd" /></span>-<span><fmt:formatDate value="${coupon.couponUseEndTime }" pattern="yyyy.MM.dd" /></i>
						</a>
					</div>
				</div>
				<p class="text-center">${coupon.couponTips }</p>
				<p class="text-center">
					<c:choose>
						<c:when test="${coupon.couponType=='满减' }">
									满<fmt:formatNumber type="number" value="${coupon.param1 }" maxFractionDigits="0" />减<fmt:formatNumber type="number" value="${coupon.param2 }" maxFractionDigits="0" />元
									</c:when>
						<c:when test="${coupon.couponType=='立减' }">
									立减<fmt:formatNumber type="number" value="${coupon.param1 }" maxFractionDigits="0" />元
									</c:when>
					</c:choose>
				</p>
				<br> <br>
				<p>
					<c:choose>
						<c:when test="${buyerSession!=null&&buyerCoupon!=null }">
							<h2 class="text-center">恭喜你，已经抢到了!</h2>
							<!-- <p class="text-center">
								<a href="show_buyer_coupon_list?s=未使用" class="btn green btn-lg">查看我的优惠券</a>
							</p> -->
						</c:when>
						<c:when test="${buyerSession!=null&&buyerCoupon==null }">
							<button id="snap_coupon_button" type="button" class="btn blue btn-lg btn-block">抢优惠券</button>
						</c:when>
					</c:choose>
				</p>
			</div>
		</c:otherwise>
	</c:choose>

	<!-- BEGIN FOOTER -->
	<!-- <div class="footer">
		<div class="container">
			<div class="row">
				<div class="col-xs-3 text-center">
					<a href="./" class="icon-btn">
						<i class="fa fa-home"></i>
						<div>首页</div>

					</a>
				</div>
				<div class="col-xs-3 text-center">
					<a href="goods_type/get_shop_goods_type" class="icon-btn">
						<i class="fa fa-list-ul"></i>
						<div>类型</div>
					</a>
				</div>
				<div class="col-xs-3 text-center">
					<a href="cart" class="icon-btn">
						<i class="fa fa-shopping-cart"></i>
						<div>购物车</div>
						<span class="badge badge-important" id="shooping_cart_icon_number"></span>
					</a>
				</div>
				<div class="col-xs-3 text-center">
					<a href="item/infocenter.jsp" class="icon-btn">
						<i class="fa fa-user"></i>
						<div>个人中心</div>
					</a>
				</div>
			</div>
		</div>
	</div> -->
	<!-- END FOOTER -->

	<c:if test="${buyerSession==null }">
		<div id="no_buyer_flag" style="display: none;"></div>
	</c:if>

	<!-- BEGIN JAVASCRIPTS(Load javascripts at bottom, this will reduce page load time) -->
	<!-- BEGIN CORE PLUGINS -->
	<script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js" type="text/javascript"></script>
	<script src="https://cdn.bootcss.com/jquery-migrate/1.2.1/jquery-migrate.min.js" type="text/javascript"></script>
	<!-- IMPORTANT! Load jquery-ui-1.10.3.custom.min.js before bootstrap.min.js to fix bootstrap tooltip conflict with jquery ui tooltip -->
	<script src="assets/plugins/jquery-ui/jquery-ui-1.10.3.custom.min.js" type="text/javascript"></script>
	<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js" type="text/javascript"></script>
	<script src="assets/plugins/bootstrap-hover-dropdown/bootstrap-hover-dropdown.min.js" type="text/javascript"></script>
	<script src="assets/plugins/jquery-slimscroll/jquery.slimscroll.min.js" type="text/javascript"></script>
	<script src="assets/plugins/jquery.blockui.min.js" type="text/javascript"></script>
	<script src="assets/plugins/jquery.cokie.min.js" type="text/javascript"></script>
	<script src="assets/plugins/uniform/jquery.uniform.min.js" type="text/javascript"></script>
	<script src="js/wow.min.js"></script>
	<script src="js/bootstrap.file-input.js"></script>
	<!-- END CORE PLUGINS -->
	<!-- BEGIN PAGE LEVEL PLUGINS -->
	<script type="text/javascript" src="https://cdn.bootcss.com/Swiper/3.0.8/js/swiper.jquery.min.js"></script>
	<script type="text/javascript" src="assets/plugins/jquery-validation/dist/jquery.validate.min.js"></script>
	<script type="text/javascript" src="assets/plugins/jquery-validation/localization/messages_zh.js"></script>
	<script type="text/javascript" src="assets/plugins/select2/select2.min.js"></script>
	<script type="text/javascript" src="assets/plugins/jquery-bootpag/jquery.bootpag.min.js"></script>
	<script type="text/javascript" src="js/jquery.form.js"></script>
	<!-- END PAGE LEVEL PLUGINS -->
	<!-- BEGIN PAGE LEVEL SCRIPTS -->
	<script src="js/app.js"></script>
	<script src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
	<!-- END PAGE LEVEL SCRIPTS -->

	<script>
		$(function()
		{
			// Initiat WOW JS
			if (isHTML5 == true)
			{
				new WOW().init();
			}
			App.init();

			$.post("wc_get_wechat_info",
			{
				"currentUrl" : location.href.split('#')[0]
			}, function(json)
			{
				wx.config(
				{
					debug : false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
					appId : json.appId, // 必填，公众号的唯一标识
					timestamp : json.timestamp, // 必填，生成签名的时间戳
					nonceStr : json.nonceStr, // 必填，生成签名的随机串
					signature : json.signature,// 必填，签名，见附录1
					jsApiList : [ 'onMenuShareTimeline', 'chooseWXPay' ]
				// 必填，需要使用的JS接口列表，所有JS接口列表见附录2
				});
				wx.ready(function()
				{
					wx.onMenuShareTimeline(
					{
						title : '', // 分享标题
						link : '', // 分享链接
						imgUrl : '', // 分享图标
						success : function()
						{
							// 用户确认分享后执行的回调函数
							alert("成功分享了");
						},
						cancel : function()
						{
							// 用户取消分享后执行的回调函数
							alert("取消分享了");
						}
					});
				});
				wx.error(function(res)
				{
				});

				var code = "${param.code}";
				if (code.length > 0)
				{
					$.post("wc_get_user_info",
					{
						'code' : code
					}, function(return_json)
					{
						if (return_json.success == true)
						{
							if ($("#no_buyer_flag").length > 0)
							{
								window.location.href = location.href.split('#')[0] + "?time=" + new Date();
							}
						}
					},
					//返回类型
					"json");
				}
				else
				{
					$.post("wc_valid_have_this_person", {}, function(valid_json)
					{
						if (valid_json.success == false)
						{

							String
							authUrl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&state=STATE#wechat_redirect";

							authUrl = authUrl.replace("APPID", json.appId);
							authUrl = authUrl.replace("REDIRECT_URI", location.href.split('#')[0]);
							authUrl = authUrl.replace("SCOPE", "snsapi_base");
							authUrl = authUrl.replace("STATE", 1);
							window.location.href = authUrl;
						}
						else
						{
							//alert("openid(validHaveThisPerson):" + valid_json.openid);
						}
					},
					//返回类型
					"json");
				}

			},
			//返回类型
			"json");
			$("#snap_coupon_button").click(function()
			{
				$.post("u_snap_coupon_do",
				{
					'id' : $("#coupon_id").val()
				}, function(json)
				{
					if (json.success == true)
					{
						//alert("抢到了，可以在个人中心看到我的优惠券");
						//window.location.href = "show_buyer_coupon_list?s=未使用";
						window.location.href = location.href.split('#')[0] + "?time=" + new Date();
					}
					else
					{
						alert(json.info);
					}
				},
				//返回类型
				"json");
			});
		});
	</script>
	<!-- END JAVASCRIPTS -->

</body>
</html>